﻿@{
    ViewBag.Title = "ContentSelectContent";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<script>
    var _SPIId = request('SPIId');
    var GridRowid = request('rowid');
    var SPContentId = request('SPContentId');
    $(function () {
        GetGrid();
    });
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["condition"] = $("#queryCondition .dropdown-text").attr('data-value');
        queryJson["keyword"] = $("#txt_Keyword").val();
        queryJson["SPIId"] = _SPIId;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../PropertyManage/SecurityPatrol/GetContentPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: 338,
            autowidth: true,
            multiselect: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "编号", name: "Code", index: "Code", width: 100, align: "left" },
                { label: "名称", name: "Name", index: "Name", width: 100, align: "left" },
                { label: "标准要求", name: "Criterion", index: "Criterion", width: 200, align: "left" },
                { label: "检查方式", name: "CheckWay", index: "CheckWay", width: 100, align: "left" },
                {
                    label: "是否必填", name: "IsNeed", index: "IsNeed", width: 80, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 1 ? "<i value=" + cellvalue + " class=\"fa fa-toggle-on\"></i>" : "<i value=" + cellvalue + " class=\"fa fa-toggle-off\"></i>";
                    }
                },
                { label: "说明", name: "Memo", index: "Memo", width: 150, align: "left" }
            ],
            rowNum: 13,
            rowList: [13, 26, 52,104],
            pager: "#gridPager",
            sortname: 'CreateDate',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (rowid, status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
                var rowIds = $gridTable.jqGrid('getDataIDs');
                for (var k = 0; k < rowIds.length; k++) {
                    var id = $gridTable.getRowData(rowIds[k]).Id;
                    if (SPContentId.indexOf(id) >= 0) {
                        $gridTable.delRowData(rowIds[k]);
                    }
                }
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#queryCondition").GetWebControls();
            queryJson["condition"] = $("#queryCondition .dropdown-text").attr('data-value');
            queryJson["keyword"] = $("#txt_Keyword").val();
            queryJson["SPIId"] = _SPIId;
            $gridTable.jqGrid('setGridParam', {
                url: "../../PropertyManage/SecurityPatrol/GetContentPageList",
                postData: { queryJson: JSON.stringify(queryJson) },
                page: 1
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //保存表单
    function AcceptClick() {
        var rowids = $("#gridTable").jqGrid('getGridParam', 'selarrrow');
        var ids = "";
        for (var i = 0; i < rowids.length; i++) {
            ids += $('#gridTable').getRowData(rowids[i]).Id + ",";
        }
        top.frames["Form"].$("#gridTable1").setCell(GridRowid, 'SPContentId', ids);
        dialogMsg("操作成功。", 1);
        dialogClose();
    }

</script>
<div class="ui-layout-center">
    <div class="center-Panel">
        <div class="titlePanel">
            <div class="title-search">
                <table>
                    <tr>
                        <td>
                            <div id="queryCondition" class="btn-group">
                                <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                <ul class="dropdown-menu">
                                    <li><a data-value="Code">编号</a>
                                    <li><a data-value="Name">名称</a>
                                </ul>
                            </div>
                        </td>
                        <td style="padding-left: 2px;">
                            <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                        </td>
                        <td style="padding-left: 5px;">
                            <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="gridPanel">
            <table id="gridTable"></table>
            <div id="gridPager"></div>
        </div>
    </div>
</div>

